<template>
  <el-row>
    <el-col>
      <avue-article :props="props" :data="data"></avue-article>
    </el-col>
    <el-col style="text-align: center">
      <el-button type="warning" size="small" @click="editNews">编辑</el-button>
      <el-button type="danger" size="small" @click="delNews">删除</el-button>
      <el-button size="small" @click="$router.go(-1)">返回</el-button>
    </el-col>
  </el-row>
</template>

<script>

  import {newsByNid, removeNews} from '@/api/operations-center/news'

  export default {
    name: "NewsManageDetail",
    data() {
      return {
        data: {
          title: '??????',
          meta: '',
          lead: '',
          body: ''
        },
        props: {
          title: 'title',
          meta: 'meta',
          lead: 'lead',
          body: 'body'
        }
      }
    },
    methods: {
      /**
       * {获取指定新闻}
       *
       * @author: 宋康
       * @date: 2022/8/25 11:32
       */
      queryNews() {
        newsByNid(this.$route.query.id || '-1').then(res => {
          if (res.status && res.data) {
            let data = res.data
            this.data.title = data.newsTitle
            this.data.meta = data.createdUser.userName
            this.data.body = data.newsBody
            this.data.lead = data.newsLead
          }
        })
      },
      /**
       * {新闻编辑}
       *
       * @author: 宋康
       * @date: 2022/8/25 11:37
       */
      editNews() {
        this.$router.push({
          name: 'NewsManageEdit',
          query: {
            type: this.$route.query.type || '-1',
            id: this.$route.query.id
          }
        })
      },
      delNews() {
        this.$confirm('此操作将永久删除该文章, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          removeNews(this.$route.query.id || '-1').then(res => {
            if (res.status) {
              this.$XModal.alert({
                content: '删除成功',
                status: 'success',
              }).then(() => {
                this.$router.go(-1);
              })
            } else {
              this.$XModal.alert({
                content: res['msg'],
                status: 'error',
              })
            }
          })
        });
      }
    },
    mounted() {
      this.queryNews();
    }
  }
</script>

<style lang="scss" scoped>

</style>
